<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="content-type" content="no-cache, must-revalidate"/>
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>公告</title>
    <link href="/front/css/bootstrap.min.css" rel="stylesheet">
    <link href="/front/css/my.css" rel="stylesheet">
    <link href="/front/css/nav.css" rel="stylesheet">

    <style>
        #notice-box li {
            margin-bottom: 10px;
        }
        #view-notice-body img {
            width: 400px;
        }
        #view-notice-body iframe {
            width: 400px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%; height: 30px; line-height: 30px; background-color: #eee;">
            <div style="flex: 5; padding: 0 10px; color: orangered">
                欢迎访问 书籍论坛系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您：{{user.name}}
                <a style="margin-left: 30px; color: blue" href="javascript:void(0)" @click="logout">退出</a>
                <a v-if="isCollect" style="margin-left: 10px" href="collectInfo.html">收藏夹</a>
            </div>
        </div>
    </div>
    <div class="nav-container">
        <div class="logo">
            <img src="/front/img/logo.png" alt="">
            书籍论坛系统
        </div>
        <ul class="nav-item-box">
            <li><a class="nav-item" href="index.html">首页</a></li>
            <li><a class="nav-item active" href="advertiserInfo.html" >公告信息</a></li>
            <li><a class="nav-item" href="dianzishuInfo.html">电子书信息</a></li>
            <li><a class="nav-item" href="shitishuInfo.html">实体书信息</a></li>
            <li><a class="nav-item" href="wendaInfo.html">问答信息</a></li>

            <li v-if="isShow"><a class="nav-item" href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li><a class="nav-item" href="/end/page/login.html" target="_blank">登录</a></li>
            <li><a class="nav-item" href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>
    <!-- /.  导航栏-->

    <div class="container" style="margin-top: 10px">
        <div class="row">
            <div class="col-md-8">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <b id="view-notice-title"></b>
                        <span style="float: right; color: #888888" id="view-notice-time"></span>
                    </div>
                    <div class="panel-body" id="view-notice-body">

                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="panel panel-default" id="notice-box">
                    <div class="panel-heading"><b>公告列表</b></div>
                    <div class="panel-body">
                        <ul id="notice-item-box">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--js库文件-->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>

<script>
    new Vue({
        el: '#wrapper',
        data: {
            user: {},
            currentId: 0,
            isShow: false,
            isCollect: false
        },

        created: function () {
            axios.get('/auth').then(res => {
                if (res.data.code === '0') {
                    this.user = res.data.data;
                    this.isShow = true;
                }
            });
            this.currentId = this.getQueryVariable('id');
            this.loadAdvertiserInfo();
        },

        methods: {
            loadAdvertiserInfo() {
                let _this = this;
                $.get('/advertiserInfo/page/all?pageSize=10', function (res) {
                    if (res.code === '0') {
                        let itemList = res.data.list;
                        let id = _this.getQueryVariable('id');
                        if(!id) {
                            id = res.data.list[0].id;
                        }
                        let $box = $("#notice-item-box");
                        $box.empty();
                        for (let item of itemList) {
                            let $item = $(`<li><a href="advertiserInfo.html?id=${item.id}">${item.name}</a></li>`);
                            if(parseInt(id) === item.id) {  // 当前选择的公告
                                $item.find('a').addClass('active');
                                // 当前展示的公告信息
                                $('#view-notice-title').text(item.name);
                                $('#view-notice-time').text(item.time);
                                $('#view-notice-body').html(item.content);
                            }
                            $box.append($item);
                        }
                    }
                })
            },
            getQueryVariable(variable) {
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                for (let i = 0; i < vars.length; i++) {
                    let pair = vars[i].split("=");
                    if (pair[0] === variable) {
                        return pair[1];
                    }
                }
                return '1';
            },
            logout() {
                axios.get("/logout").then(res => {
                    if(res.data.code === '0') {
                        location.href = '/front/index.html';
                    } else {
                        msg('error', res.data.msg);
                    }
                })
            }
        }
    })
</script>
</body>
</html>